const GET = 'get';
const POST = 'post';


//const baseURL = 'https://anjingbao.dianjingkeji.net/prod-api'
const baseURL = 'https://anjingbao.anjingbao.net/prod-api'
//const baseURL = 'http://192.168.0.5:8066';  // 接口请求地址
//const baseURL = 'https://47b826g831.oicp.vip';  // 接口请求地址
 
module.exports = function (options) {
    return new Promise(function(resolve, reject) {
        let header = {
            'content-type': 'application/json'
        };
        wx.request({
            url: baseURL + options.url,
            method: options.method,
            //data: options.method === POST ? JSON.stringify(options.data) : options.data,
           data: options.data,
            header: options.header,
            success(res) {
              // 请求到接口前页面展示loading
              if(res.data.code == 401)
              {
                wx.setStorageSync('openId','')
                wx.setStorageSync('unionId','')
                wx.setStorageSync('nickName','')
                wx.setStorageSync('token','')
                wx.setStorageSync('phone','')
                wx.setStorageSync('memberId','')
                wx.setStorageSync('win','')
                wx.setStorageSync('imgUrls','')
                wx.setStorageSync('memberName','')
                wx.setStorageSync('memberName','')


                  wx.setStorageSync('onshow',true )
                  wx.switchTab({
                    url: '/pages/center/center',
                  })
              }
              else
              {
                 wx.showLoading ({
                   title: '加载中...',
                   success: function() {
                   
                     resolve(res.data)
                  }
                 })
              }
              
            },
            fail: function (err) {
              // 请求失败
              reject(err)
              wx.showToast({
                  title: '网络繁忙，请稍后重试~',
                  icon: 'none'
              })
             },
             complete: function () {
                // 配对使用（loading消失）
                 wx.hideLoading();
             }
        })
    })
}

